package com.controller.nginxserver;

import org.lucksyc.utilindependent.resultview.core.data.ViewData;
import org.lucksyc.utilindependent.resultview.seed.deal.ViewBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.model.ServiceQuery;
import com.upper.service.nginxserver.NginxServerInterface;

/**
 * @author wsq
 */
@Controller
@RequestMapping("/nginxserver")
public class NginxServerController {
	private static final Logger log = LoggerFactory.getLogger(NginxServerController.class);
	
	@Autowired
	ViewBuilder viewBuilder;
	
	@Autowired
	NginxServerInterface nginxServerInterface;
	
	/*
	 * ==============================
	 */
	@ResponseBody
	@GetMapping("/getServiceList")
	public ViewData getServiceList(boolean typeBs) {
		log.debug("getServiceList.");
		try {
			return nginxServerInterface.getServiceList(typeBs);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/saveService")
	public ViewData saveService(ServiceQuery query) {
		log.debug("getServiceList.");
		try {
			return nginxServerInterface.saveService(query);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/delService")
	public ViewData delService(boolean typeBs,String id) {
		log.debug("delService.");
		try {
			return nginxServerInterface.delService(typeBs, id);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
	/*
	 * ==============================
	 */
	@ResponseBody
	@GetMapping("/getAllIpList")
	public ViewData getAllIp() {
		log.debug("getServerIpList.");
		try {
			return nginxServerInterface.getAllIp();
		} catch (Exception e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/getLocalIpList")
	public ViewData getLocalIp() {
		log.debug("getLocalIp.");
		try {
			return nginxServerInterface.getLocalIp();
		} catch (Exception e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/previewjson")
	public ViewData previewjson() {
		try {
			return nginxServerInterface.previewjson();
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}
}
